# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'Thread' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for Thread
  pod 'Masonry', '~> 1.1'
  pod 'YYKit', '~> 1.0'
  pod 'SDWebImage', '~> 5.15'
  pod 'AFNetworking', '~> 4.0'
  pod 'Aspects', '~> 1.4'
  pod 'ReactiveObjC', '3.1.1'

  pod 'MLeaksFinder', :configurations => ['Debug']
  pod 'DoraemonKit', '~> 3.1', :configurations => ['Debug']
  pod 'LookinServer', :configurations => ['Debug']

end


post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
    end
  end
  
  installer.pods_project.build_configurations.each do |config|
    config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
  end
  
  
  #处理 fishhook
  find_and_replace("Pods/FBRetainCycleDetector/fishhook/fishhook.c",
                   "indirect_symbol_bindings[i] = cur->rebindings[j].replacement;",
                   "if (i < (sizeof(indirect_symbol_bindings) / sizeof(indirect_symbol_bindings[0]))) {\n\
                      indirect_symbol_bindings[i]=cur->rebindings[j].replacement;\n \
                   }")
                   
                   #处理 layoutCache[currentClass] = ivars报错
                   find_and_replace("Pods/FBRetainCycleDetector/FBRetainCycleDetector/Layout/Classes/FBClassStrongLayout.mm",
                                    "layoutCache[currentClass] = ivars;",
                                    "layoutCache[(id<NSCopying>)currentClass] = ivars;")
                                    
                                    installer.generated_projects.each do |project|
                                      project.targets.each do |target|
                                        target.build_configurations.each do |config|
                                          config.build_settings["DEVELOPMENT_TEAM"] = "J5JS5MK8MN"
                                        end
                                      end
                                    end
end

def find_and_replace(dir, findstr, replacestr)
  Dir[dir].each do |name|
    FileUtils.chmod("+w", name) #add
    text = File.read(name)
    replace = text.gsub(findstr,replacestr)
    if text != replace
      puts "Fix: " + name
      File.open(name, "w") { |file| file.puts replace }
      STDOUT.flush
    end
  end
  Dir[dir + '*/'].each(&method(:find_and_replace))
end

